﻿#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#include <QSGRendererInterface>
#include <QFont>
#include <QQuickStyle>
#include <QQmlContext>
#include "qquickflatwindowhandler.h"
#include "api/apiprovider.h"

int main(int argc, char *argv[])
{
    QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication::setApplicationName("ToDoer");
    QApplication::setQuitOnLastWindowClosed(false);

    QApplication app(argc, argv);
    QQmlApplicationEngine engine;
    QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);

    engine.addImportPath(QStringLiteral("qrc:/"));

    qmlRegisterType<QQuickFlatWindowHandler>("Qt.FlatWindow", 1, 0, "QQuickFlatWindowHandler");
    ApiProvider api;
    engine.rootContext()->setContextProperty("ApiProvider",&api);

    QFont font;
    font.setFamily("Microsoft YaHei");
    app.setFont(font);
    QQuickStyle::setStyle("Fusion");

    const QUrl url(QStringLiteral("qrc:/ui/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
